package com.example.partner.adapter.find;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.partner.R;
import com.example.partner.model.vo.PostCommentVO;
import java.util.ArrayList;
import java.util.List;

public class ReplyAdapter extends RecyclerView.Adapter<ReplyAdapter.ReplyViewHolder> {

    private List<PostCommentVO> replyList = new ArrayList<>();

    public ReplyAdapter(List<PostCommentVO> replyList) {
        this.replyList = replyList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ReplyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_reply, parent, false);
        return new ReplyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ReplyViewHolder holder, int position) {
        PostCommentVO reply = replyList.get(position);
        // 设置回复内容
        holder.textViewReplyerName.setText(reply.getUsername());
        holder.textViewReplyContent.setText(reply.getContent());
        holder.textViewRepliedToName.setText(reply.getName());
    }

    @Override
    public int getItemCount() {
        if (replyList == null) {
            return 0;
        }
        return replyList.size();
    }

    static class ReplyViewHolder extends RecyclerView.ViewHolder {
        TextView textViewReplyerName,textViewReplyTo,textViewRepliedToName;
        TextView textViewReplyContent;

        ReplyViewHolder(@NonNull View itemView) {
            super(itemView);
            textViewReplyerName = itemView.findViewById(R.id.textViewReplyerName);
            textViewReplyContent = itemView.findViewById(R.id.textViewReplyContent);
            textViewRepliedToName = itemView.findViewById(R.id.textViewRepliedToName);
            textViewReplyTo = itemView.findViewById(R.id.textViewReplyTo);
        }
    }
}
